import { useEffect, useState } from "react";

export function useTableHeight(offset: number) {
  const [tableHeight, setTableHeight] = useState<number>(0);

  useEffect(() => {
    const calculateTableDimensions = () => {
      const windowHeight = window.innerHeight;
      const availableHeight = windowHeight - offset;
      setTableHeight(availableHeight);
    };

    calculateTableDimensions();
    window.addEventListener("resize", calculateTableDimensions);

    return () => {
      window.removeEventListener("resize", calculateTableDimensions);
    };
  }, [offset]);

  return tableHeight;
}